﻿#include "time.h"
#include "time_utility.h"

namespace breaking
{
	int64_t time::s_current_time_deviation = 0;

	time::time() :m_millisecond(0)
	{

	}

	time::time(uint64_t msec) :m_millisecond(msec)
	{

	}

	time::time(const time& _time) :m_millisecond(_time.m_millisecond)
	{

	}

	time::~time()
	{

	}

	time time::current_time()
	{
		return time_utility::GetCurrentMSec() + s_current_time_deviation;
	}

	void time::set_current_time_deviation(uint64_t new_current_time)
	{
		s_current_time_deviation = new_current_time - time_utility::GetCurrentMSec();
	}

	void time::set_time_deviation(int64_t deviation)
	{
		s_current_time_deviation = deviation;
	}

	int64_t time::get_time_deviation()
	{
		return s_current_time_deviation;
	}

	uint64_t time::msec() const
	{
		return m_millisecond;
	}

	uint32_t time::sec() const
	{
		return (uint32_t)(m_millisecond / 1000);
	}

	bool time::operator<(const time& _time) const
	{
		return m_millisecond < _time.m_millisecond;
	}

	bool time::operator>(const time& _time) const
	{
		return m_millisecond > _time.m_millisecond;
	}

	bool time::operator>=(const time& _time) const
	{
		return !operator<(_time);
	}

	bool time::operator<=(const time& _time) const
	{
		return !operator>(_time);
	}

	bool time::operator==(const time& _time) const
	{
		return m_millisecond == _time.m_millisecond;
	}

	bool time::operator!=(const time& _time) const
	{
		return !operator==(_time);
	}

	const time& time::operator+= (const time& _time)
	{
		m_millisecond += _time.m_millisecond;
		return *this;
	}

	const time& time::operator-= (const time& _time)
	{
		m_millisecond -= _time.m_millisecond;
		return *this;
	}
}
